package com.sskj.gcc.ui.fragment;


import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sskj.common.util.ClickUtil;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.game.GameNotificationBean;
import com.sskj.gcc.presenter.game.GameFragmentPresenter;
import com.sskj.gocoin.common.adapter.BaseAdapter;
import com.sskj.gocoin.common.adapter.ViewHolder;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.Unbinder;


public class GameBottomNotificationFragment extends GameBaseFragment {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    Unbinder unbinder;
    private BaseAdapter<GameNotificationBean.DataBean> mAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.app_fragment_game_notification;
    }

    @Override
    public GameFragmentPresenter getPresenter() {
        return new GameFragmentPresenter();
    }

    @Override
    public void initView() {
        ArrayList<GameNotificationBean.DataBean> arrayList = new ArrayList();

        GradientDrawable background0 = new GradientDrawable();
        background0.setCornerRadius(10);
        background0.setColor(Color.parseColor("#F3F2F0"));

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new BaseAdapter<GameNotificationBean.DataBean>(R.layout.app_adapter_game_notification, arrayList, recyclerView) {
            @Override
            public void bind(ViewHolder holder, GameNotificationBean.DataBean data) {
                Glide.with(getActivity()).load(background0).into((ImageView) holder.getView(R.id.iv_background));
                holder.setText(R.id.tv_title, data.getTitle());
                holder.setText(R.id.tv_content, Html.fromHtml(data.getContent()));
                holder.setText(R.id.tv_time, data.getCreated_at());
                TextView tvContent = holder.getView(R.id.tv_content);
                ClickUtil.click(holder.itemView, new ClickUtil.Click() {
                    @Override
                    public void click() {
                        Glide.with(getActivity()).load(tvContent.isShown() ? R.drawable.app_home_game_notification_arrow_down : R.drawable.app_home_game_notification_arrow_up).into((ImageView) holder.getView(R.id.iv_arrow));
                        tvContent.setVisibility(tvContent.isShown() ? View.GONE : View.VISIBLE);
                    }
                });
            }
        };
        mPresenter.getSystemPostsList();
    }

    @Override
    public void getSystemPostsListSuccess(GameNotificationBean gameNotificationBean) {
        super.getSystemPostsListSuccess(gameNotificationBean);
        if (gameNotificationBean.getData() != null) {
            mAdapter.setNewData(gameNotificationBean.getData());
        }
    }
}
